﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using Framework.Graphics;
using Framework.Graphics.Light;
using Framework.Graphics.Light.Shadow;
using Framework.GameObjectManagment;

namespace Framework.GameObjectManagment.GameObjects
{
    public class Player:GameObject
    {
        private Texture2D _back, _front;

        public Texture2D Back
        {
            get { return _back; }
        }

        public override void Init()
        {
            this.CastShadows = true;
            base.Init();
        }

        public override void LoadContent(ContentManager cm)
        {
            _back = cm.Load<Texture2D>("GameObject/Player/Robot_Wheels");
            _front = cm.Load<Texture2D>("GameObject/Player/Robot");

            base.LoadContent(cm);
        }

        public override void Update()
        {
            base.Update();
        }

        public override void Draw()
        {
            double angle = Math.Atan2(362 + 50 - Framework.GameStateManagment.Input.MS.Y, 512 + 50 - Framework.GameStateManagment.Input.MS.X);

            //Camera.SpriteBatch.Begin();
            Camera.DrawWithoutMovement(_back, new Vector2(512, 362), null, Color.White, 0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0f);
            Camera.DrawWithoutMovement(_front, new Vector2(512 + 50, 362 + 50), null, Color.White, (float)angle - MathHelper.ToRadians(90f),
                new Vector2(_front.Width / 2), 0.5f, SpriteEffects.None, 0f);
            //Camera.SpriteBatch.End();

            base.Draw();
        }

        public override void DrawShadows(LightArea LA)
        {
            double angle = Math.Atan2(362 + 50 - Framework.GameStateManagment.Input.MS.Y, 512 + 50 - Framework.GameStateManagment.Input.MS.X);

            //Camera.SpriteBatch.Begin();
            Camera.DrawWithoutMovement(_back, LA.ToRelativePosition(new Vector2(512, 362)), null, Color.White, 0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0f);
            Camera.DrawWithoutMovement(_front, LA.ToRelativePosition(new Vector2(512 + 50, 362 + 50)), null, Color.White, (float)angle - MathHelper.ToRadians(90f),
                new Vector2(_front.Width / 2), 0.5f, SpriteEffects.None, 0f);
            //Camera.SpriteBatch.End();
        }
    }
}
